package game_logic.control.ai;

import game_logic.Controller;
import game_logic.GameFactory;
import game_logic.control.GameController;
import game_logic.util.Vec2;

import javax.swing.*;

/**
 * AI启动
 */
public class Start extends Thread{
    private final GameController controller;
    public Start(){
        controller =(GameController) GameFactory.makeGame("", true, true,null,0);
        controller.gameStart();
    }
    public void run(){
        while(!controller.getBoard().isGameOver()) {
            if(controller.getBoard().getCurrentPlayer()==0){
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                continue;
            }
            SearchModel searchModel = new SearchModel();
            AlphaBetaNode result = searchModel.search(controller.getBoard());
            Vec2 resPos = controller.getPiecePos(result.piece);
            controller.move(resPos.x, resPos.y, result.to[0], result.to[1]);
        }
        System.out.println("Over");
//        if (controller.getBoard().getWinner() == controller.getBoard().getCurrentPlayer()%2) {
//            JOptionPane.showMessageDialog(null, "黑方胜利！");
//        }
    }
}
